package com.ronglian.iot.utils;

import cn.hutool.core.collection.CollUtil;

import java.math.BigDecimal;
import java.util.List;

public class NumUtil {
    public static BigDecimal multiplyRatio(BigDecimal value,BigDecimal ratio){
        if (value==null || ratio==null){
            return null;
        }
        return ratio.multiply(value).divide(new BigDecimal(100));
    }
    public static BigDecimal sumBigDecimal(List<BigDecimal> decimalList){
        if (CollUtil.isEmpty(decimalList)){
            return BigDecimal.ZERO;
        }
        return decimalList.stream().filter(obj->obj!=null).reduce(BigDecimal.ZERO,BigDecimal::add).setScale(2,BigDecimal.ROUND_HALF_UP);

    }
}
